package com.hhs.storage.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hhs.storage.util.DateEasy;
import com.hhs.storage.util.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 工作时间页面参数
 */
@Data
public class WorkDayBean {
    /**
     * 0.部门 1.个人
     */
    @ApiModelProperty(name="type",value = "0.部门 1.个人",required = true)
    private Integer type;
    /**
     * type 为0时间传部门id
     * type 为1传个人id
     */
    @ApiModelProperty(name="id",value = "type为0时间传部门id,type为1传个人id",required = true)
    private String id;

    /**
     * 每天上班数
     * 0,8,0,8,8,8,14
     * 第一个是周日，0表示不上班
     */
    @ApiModelProperty(name="workDaysValue",value = "上班时间格式为：0,8,0,8,6,12,1 第一个是周一，0表示不上班",required = false)
    private String workDaysValue;
    /**
     * 上班类型
     * 0正常班，1大小周，2隔天上，3自由定义,4总时数
     */
    @ApiModelProperty(name="workType",value = "0正常班，1大小周，2隔天上，3自由定义,4总时数",required = false)
    private Integer workType;
    /**
     * 人物类型
     * 0普通人，1.领导(机动时间上班的人)
     */
    @ApiModelProperty(name="personType",value = "0普通人，1.领导(机动时间上班的人)",required = true)
    private Integer personType;
    /**
     * 人物类型
     * 一周工作的总小时数
     */
    @ApiModelProperty(name="totalHours",value = "一周工作的总小时数，只有领导才设置",required = false)
    private String totalHours;
    /**
     * 当前修改周的时间
     */
    @ApiModelProperty(name="startDate",value = "修改周的时间，上一周下一周时要从前台再传过来",required = false)
    @JSONField(format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate startDate;
    /**
     * 当前修改周的从周一到周天所有时间第一个是周一
     */
    @ApiModelProperty(name="displayDates",value = "当前修改周的从周一到周天所有时间第一个是周一",required = false)
    private List<String> displayDates;

    public static WorkDayBean zrAttendanceSettingToWorkDayBean(ZrAttendanceSetting listSetting) {
        WorkDayBean wdb=new WorkDayBean();
        wdb.setId(listSetting.getTargetId());
        wdb.setType(listSetting.getType());
        wdb.setWorkType(listSetting.getWorkType());
        wdb.setStartDate(listSetting.getStartDate());
        wdb.setPersonType(listSetting.getPersonType());
        if(listSetting.getAtt1()!=null){
            wdb.setWorkDaysValue(listSetting.getAtt1()+","+listSetting.getAtt2()+","+listSetting.getAtt3()+","+listSetting.getAtt4()+","+listSetting.getAtt5()+","+listSetting.getAtt6()+","+listSetting.getAtt7());
        }
        if(listSetting.getTotalHours()!=null){
            wdb.setTotalHours(listSetting.getTotalHours()+"");
        }
        List<String> displayDates=new ArrayList<>();
        DateEasy da = new DateEasy(listSetting.getStartDate());
        displayDates.add(da.toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        displayDates.add(da.addDate(1).toYYYYhMMhDD());
        wdb.setDisplayDates(displayDates);
        return wdb;
    }

    /**
     * 得到默认的显示WorkDayBean
     * @param inputParam
     * @return
     */
    public static WorkDayBean getInstanceDefault(InputParam inputParam){
        DateEasy morning=null;
        if(inputParam.getGoDate()!=null){
            morning= DateEasy.getTimesWeekMorning(new DateEasy(inputParam.getGoDate()));
        }else if(inputParam.getStartDate()!=null){
            morning= DateEasy.getTimesWeekMorning(new DateEasy(inputParam.getStartDate()));
        }
        WorkDayBean wkb=new WorkDayBean();
        wkb.setId(inputParam.getId());
        wkb.setType(inputParam.getType());
        wkb.setStartDate(morning.toLocalDate());
        wkb.setPersonType(inputParam.getPersonType());
        if(inputParam.getPersonType()==null||inputParam.getPersonType()==0){
            wkb.setWorkType(0);
            wkb.setWorkDaysValue(ZrAttendanceSetting.WORKVALUE);
        }else if(inputParam.getPersonType()==1){
            wkb.setWorkType(4);
            wkb.setTotalHours("28");
        }
        List<String> displayDates=new ArrayList<>();
        displayDates.add(morning.toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        displayDates.add(morning.addDate(1).toYYYYhMMhDD());
        wkb.setDisplayDates(displayDates);
        return wkb;
    }
}
